package jsu.lipengcheng.trafficnet.service.Impl;

import jsu.lipengcheng.trafficnet.common.BeanThread;
import jsu.lipengcheng.trafficnet.mapper.NewsMapper;
import jsu.lipengcheng.trafficnet.pojo.News;
import jsu.lipengcheng.trafficnet.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PutMapping;

import java.time.LocalDate;
import java.util.List;

@Service
public class NewServiceImpl implements NewsService {
    @Autowired
    private NewsMapper newsMapper;

    /**
     * 根据id查询
     * @param id
     * @return
     */
    public News selectbyid(int id) {
        News news= newsMapper.selectById(id);
        return news;
    }

    @Override
    public List<News> selectall() {
        List<News> newsList = newsMapper.selectList(null);
        return newsList;
    }

    /**
     * 添加新闻
     * @param news
     */
    public void addnews(News news) {
        news.setTime(LocalDate.now().toString());
        news.setUserId(BeanThread.get());
        newsMapper.insert(news);
    }


    /**
     * 批量删除
     * @param ids
     */
    public void deletenews(List<Integer> ids) {
        newsMapper.deleteByIds(ids);
    }

    public void updatenews(News news) {
        newsMapper.updateById(news);
    }

    /**
     * 修改
     * @param news
     */
    public void updatanews(News news) {
        newsMapper.updateById(news);
    }

    @Override
    public int selectsum() {
       int sum= newsMapper.selectsum();
        return sum;
    }
}
